<template>
  <div class="zhuanjia">
    <!-- 头部 专家义诊 -->
    <van-nav-bar title="专家义诊">
      <template #left>
        <van-icon
          name="arrow-left"
          size="23"
          color="#000000"
          @click="hanclick"
        />
      </template>
      <template #right>
        <van-icon name="chat-o" size="23" color="#000000" />
      </template>
    </van-nav-bar>
    <!-- banner图片 -->
    <div class="banner">
      <img src="../assets/img/banner11.png" alt="" />
    </div>
    <!-- 医生 -->
    <div class="yins">
      <div class="le">你本周还有<i>2次</i>义诊机会</div>
      <div class="ri">
        <span class="span1">本地医生</span>
        <span class="span2">全国医生</span>
      </div>
    </div>
    <!-- 科室 -->
    <ul class="Department">
      <li
        v-for="(item, index) in Department"
        :key="item"
        :class="{ active: num == index }"
        @click="zhuanclick(index, item.title)"
      >
        {{ item.title }}
      </li>
    </ul>
    <router-view></router-view>
  </div>
</template>
<script>
import { ref, onMounted, computed, provide } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
export default {
  setup() {
    const store = useStore();
    const router = useRouter();
    const num = ref(0);
    const Department = ref([
      {
        title: "妇产科",
        url: "/studio/fuchan",
      },
      {
        title: "儿科",
        url: "/studio/erke",
      },
      {
        title: "内科",
        url: "/studio/neike",
      },
      {
        title: "外科",
        url: "/studio/waike",
      },
      {
        title: "耳鼻喉科",
        url: "/studio/erpihou",
      },
      {
        title: "眼科",
        url: "/studio/yanke",
      },
      {
        title: "皮肤科",
        url: "/studio/pifike",
      },
      {
        title: "中医科",
        url: "/studio/zhongyi",
      },
      {
        title: "心理科",
        url: "/studio/xinli",
      },
      {
        title: "肿瘤科",
        url: "/studio/zhongliu",
      },
      {
        title: "生殖中心",
        url: "/studio/shengchi",
      },
      {
        title: "口腔科",
        url: "/studio/kouqing",
      },
    ]);
    const hanclick = () => {
      router.push("/home");
    };
    const zhuanclick = (index, a) => {
      num.value = index;
      setRecommend(a);
    };
    //计算属性拿取vuex里面的数据
    const zhuanjia = computed(() => store.state.recommend);
    //初始化渲染推荐数据
    onMounted(() => {
      setRecommend("妇产科");
    });
    //调用active函数
    const setRecommend = (a) => store.dispatch("getRecommend", a);
    //依赖注入
    provide("zhuanjia", zhuanjia);

    // setTimeout(() => {
    //   console.log(zhuanjia.value);
    // }, 1000);
    return {
      Department,
      num,
      hanclick,
      zhuanclick,
      setRecommend,
      zhuanjia,
    };
  },
};
</script>

<style lang="less">
.zhuanjia {
  background: white;
  .van-nav-bar__title {
    font-size: 20px;
    font-weight: 400;
  }
  .banner {
    width: 100%;
    img {
      width: 100%;
    }
  }
  .yins {
    margin: 10px 0;
    text-align: center;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5px;
    width: 352px;
    height: 43px;
    background: #f8f8f8;
    border-radius: 5px;
    margin-left: 11px;
    .le {
      font-size: 13px;
      font-weight: 400;
      color: #333333;
      line-height: 43px;
      i {
        color: #e99971;
      }
    }
    .ri {
      span {
        display: inline-block;
      }
      .span1 {
        // width: 58px;
        padding: 0 5px;
        height: 28px;
        border: 1px solid #e67e4a;
        border-radius: 5px 0px 0px 5px;
        font-size: 12px;
        font-weight: 500;
        color: #ff7e06;
        line-height: 28px;
      }
      .span2 {
        position: relative;
        top: -1px;
        // width: 58px;
        padding: 0 5px;
        height: 28px;
        background: #fe7110;
        font-size: 12px;
        font-weight: 500;
        color: #ffffff;
        line-height: 28px;
        border-radius: 0px 4px 4px 0px;
      }
    }
  }
  .Department {
    width: 100%;
    padding: 0 10px;
    display: flex;
    justify-content: space-evenly;
    flex-wrap: wrap;
    li {
      text-align: center;
      margin-bottom: 10px;
      width: 81px;
      height: 30px;
      font-size: 15px;
      opacity: 0.8;
      font-weight: 500;
      color: #666666;
      line-height: 30px;
    }
    .active {
      border: 1px solid #a1c1b1;
      border-radius: 15px;
      color: #1a8bd3;
      background: #eff6fe;
    }
  }
}
</style>
